﻿using CallCenter.Data.Base;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CallCenter.Data.BizUtilities
{
   public class ccCallHistory:BaseUtility
    {

        public ccCallHistory(DataManager manager)
            :base(manager)
        { }
       
            public DataTable GetAll()
            {
              string sql = "SELECT * FROM ccCallHistory";
            return this.Factory.ExecuteTable(sql);
            }

            public int Insert(int callLogIds, string note)
            {
                int nRtn = -1;
              string sql =  "INSERT INTO ccCallHistory(callLogIds, note) VALUES (@code, @note) SELECT @ID = @@IDENTITY";
            using (var cmd = this.Factory.GetCommand(sql))
            {
                this.Factory.AddParameter(cmd, "@callLogId", SqlDbType.Int, 10, callLogIds);
                this.Factory.AddParameter(cmd, "@note", SqlDbType.VarChar, 1000, note);

               // this.Factory.ExecuteNonQuery(cmd);


                var param = this.Factory.AddParameter(cmd, "@pResult", System.Data.SqlDbType.NVarChar, 500, null);
                param.Direction = System.Data.ParameterDirection.Output;

              return  this.Factory.ExecuteNonQuery(cmd);
            }
            //cmdInsert.Parameters.Add("@ID", SqlDbType.Int);
            //cmdInsert.Parameters["@ID"].Direction = ParameterDirection.Output;

           // return nRtn;
            }

            public int Update(int id, int callLogIds, string note)
            {
                int nRtn = -1;
                string sql = "UPDATE ccCallHistory SET callLogIds=@callLogIds, note=@note WHERE id=@id";

            using (var cmd = this.Factory.GetCommand(sql))
            {
                this.Factory.AddParameter(cmd, "@callLogId", SqlDbType.Int, 10, callLogIds);
                this.Factory.AddParameter(cmd, "@note", SqlDbType.Int, 10, note);
                 this.Factory.AddParameter(cmd, "@Id", SqlDbType.Int, 10, id);
                return this.Factory.ExecuteNonQuery(cmd);
            }         
                
              //  return nRtn;
            }


            public void Delete(int nCallHistoryId) //delete the row of data using the id passed to the function
            {
               string sql = "DELETE FROM ccCallHistory " +  "WHERE ID = @ID ";

            using (var cmd = this.Factory.GetCommand(sql))
            {

                this.Factory.AddParameter(cmd, "@ID", SqlDbType.Int, 4, nCallHistoryId);
                this.Factory.ExecuteNonQuery(cmd);
            }
        }

            public void DeleteAll() //delete all the rows in the data.
            {
              string sql= "DELETE FROM ccCallHistory ";
              this.Factory.ExecuteTable(sql);
        }
        }
    }
